package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.RestIdentityLink;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.CaseInstanceIdentityLinksApi")
public class CaseInstanceIdentityLinksApi {
    private ApiClient apiClient;

    public CaseInstanceIdentityLinksApi() {
        this(new ApiClient());
    }

    @Autowired
    public CaseInstanceIdentityLinksApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Add an involved user to a case instance
     * Note that the groupId in Response Body will always be null, as it’s only possible to involve users with a case instance.
     * <p><b>200</b> - successful operation
     * <p><b>201</b> - Indicates the case instance was found and the link is created.
     * <p><b>400</b> - Indicates the requested body did not contain a userId or a type.
     * <p><b>404</b> - Indicates the requested case instance was not found.
     * @param caseInstanceId The caseInstanceId parameter
     * @param body The body parameter
     * @return RestIdentityLink
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public RestIdentityLink createCaseInstanceIdentityLinks(String caseInstanceId, RestIdentityLink body) throws RestClientException {
        Object postBody = body;

        // verify the required parameter 'caseInstanceId' is set
        if (caseInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'caseInstanceId' when calling createCaseInstanceIdentityLinks");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("caseInstanceId", caseInstanceId);
        String path = UriComponentsBuilder.fromPath("/cmmn-runtime/case-instances/{caseInstanceId}/identitylinks").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<RestIdentityLink> returnType = new ParameterizedTypeReference<RestIdentityLink>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Remove an involved user to from case instance
     *
     * <p><b>204</b> - Indicates the case instance was found and the link has been deleted. Response body is left empty intentionally.
     * <p><b>404</b> - Indicates the requested case instance was not found or the link to delete does not exist. The response status contains additional information about the error.
     * @param caseInstanceId The caseInstanceId parameter
     * @param identityId The identityId parameter
     * @param type The type parameter
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public void deleteCaseInstanceIdentityLinks(String caseInstanceId, String identityId, String type) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'caseInstanceId' is set
        if (caseInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'caseInstanceId' when calling deleteCaseInstanceIdentityLinks");
        }

        // verify the required parameter 'identityId' is set
        if (identityId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'identityId' when calling deleteCaseInstanceIdentityLinks");
        }

        // verify the required parameter 'type' is set
        if (type == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'type' when calling deleteCaseInstanceIdentityLinks");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("caseInstanceId", caseInstanceId);
        uriVariables.put("identityId", identityId);
        uriVariables.put("type", type);
        String path = UriComponentsBuilder.fromPath("/cmmn-runtime/case-instances/{caseInstanceId}/identitylinks/users/{identityId}/{type}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
        apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get a specific involved people from case instance
     *
     * <p><b>200</b> - Indicates the case instance was found and the specified link is retrieved.
     * <p><b>404</b> - Indicates the requested case instance was not found or the link to delete does not exist. The response status contains additional information about the error.
     * @param caseInstanceId The caseInstanceId parameter
     * @param identityId The identityId parameter
     * @param type The type parameter
     * @return RestIdentityLink
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public RestIdentityLink getCaseInstanceIdentityLinks(String caseInstanceId, String identityId, String type) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'caseInstanceId' is set
        if (caseInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'caseInstanceId' when calling getCaseInstanceIdentityLinks");
        }

        // verify the required parameter 'identityId' is set
        if (identityId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'identityId' when calling getCaseInstanceIdentityLinks");
        }

        // verify the required parameter 'type' is set
        if (type == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'type' when calling getCaseInstanceIdentityLinks");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("caseInstanceId", caseInstanceId);
        uriVariables.put("identityId", identityId);
        uriVariables.put("type", type);
        String path = UriComponentsBuilder.fromPath("/cmmn-runtime/case-instances/{caseInstanceId}/identitylinks/users/{identityId}/{type}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<RestIdentityLink> returnType = new ParameterizedTypeReference<RestIdentityLink>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get involved people for case instance
     * Note that the groupId in Response Body will always be null, as it’s only possible to involve users with a case instance.
     * <p><b>200</b> - Indicates the case instance was found and links are returned.
     * <p><b>404</b> - Indicates the requested case instance was not found.
     * @param caseInstanceId The caseInstanceId parameter
     * @return List&lt;RestIdentityLink&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<RestIdentityLink> listCaseInstanceIdentityLinks(String caseInstanceId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'caseInstanceId' is set
        if (caseInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'caseInstanceId' when calling listCaseInstanceIdentityLinks");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("caseInstanceId", caseInstanceId);
        String path = UriComponentsBuilder.fromPath("/cmmn-runtime/case-instances/{caseInstanceId}/identitylinks").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<RestIdentityLink>> returnType = new ParameterizedTypeReference<List<RestIdentityLink>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
